package com.cqjtu.tto.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckRole;
import com.cqjtu.tto.service.DepartmentService;
import com.cqjtu.tto.vo.Results;
import com.cqjtu.tto.vo.params.DepartmentParam;
import com.cqjtu.tto.vo.params.UpdateDepartmentParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * @author：monkey-L
 * @description:
 * @date: 17:15 2021/12/11
 */
@RestController
@Api(tags = "部门模块")
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    //    @SaCheckPermission("department-add")
//    @SaCheckRole("admin")
    @PostMapping("departmentAdd")
    @ApiOperation(value = "添加部门")
    public Results departmentAdd(@RequestBody DepartmentParam departmentParam) {
        return departmentService.departmentAdd(departmentParam);
    }

    //    @SaCheckPermission("department-delete")
//    @SaCheckRole("admin")
    @PostMapping("departmentDelete")
    @ApiOperation(value = "删除部门",notes = "根据名字删除部门")
    public Results departmentDelete(String departmentName) {
        return departmentService.departmentDelete(departmentName);
    }

    //    @SaCheckPermission("department-update")
//    @SaCheckRole("admin")
    @PostMapping("departmentUpdate")
    @ApiOperation(value = "更新部门")
    public Results departmentUpdate(@RequestBody UpdateDepartmentParam updateDepartmentParam) {
        return departmentService.departmentUpdate(updateDepartmentParam);
    }

    //    @SaCheckPermission("department-select")
//    @SaCheckRole("admin")
    @PostMapping("departmentSelectOne")
    @ApiOperation(value = "查询部门",notes = "根据名字查询部门")
    public Results departmentSelectOne(String departmentName) {
        return departmentService.departmentSelectOne(departmentName);
    }

//    @SaCheckRole("admin")
    @PostMapping("departmentSelectList")
    @ApiOperation(value = "查询所有部门")
    public Results departmentSelectList() {
        return departmentService.departmentSelectList();
    }

//    @SaCheckRole("admin")
    @PostMapping("departmentExport")
    @ApiOperation(value = "部门表打印")
    public void departmentExport(HttpServletResponse response) {
        departmentService.departmentExport(response);
    }
}
